package com.das.mechanic_base.widget;

import android.content.Context;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.das.mechanic_base.R;
import com.das.mechanic_base.adapter.alone.X3UnCompleteAdapter;
import com.das.mechanic_base.base.X3BaseBottomSheetDialog;
import com.das.mechanic_base.bean.alone.UnCompleteBean;

import java.util.List;

public class X3UnCompleteDialog extends X3BaseBottomSheetDialog implements X3UnCompleteAdapter.IOnClickToAlone {

    private TextView tv_title;

    private X3MaxHeightRecyclerView rlv_item;
    private X3UnCompleteAdapter unCompleteAdapter;

    public X3UnCompleteDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean getDialogCancel() {
        return false;
    }

    @Override
    public void initView() {
        tv_title = findViewById(R.id.tv_title);
        rlv_item = findViewById(R.id.rlv_item);

        rlv_item.setLayoutManager(new LinearLayoutManager(mContext));
        unCompleteAdapter = new X3UnCompleteAdapter(mContext);
        rlv_item.setAdapter(unCompleteAdapter);
        unCompleteAdapter.setiOnClickToAlone(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.x3_uncomplete_dialog;
    }

    public void showUnComplete(List<UnCompleteBean> unCompleteBeans) {
        tv_title.setText(String.format(mContext.getString(R.string.x3_uncomplete_title,unCompleteBeans.size())));
        if (unCompleteAdapter != null) {
            unCompleteAdapter.changeUnComplete(unCompleteBeans);
        }
    }

    @Override
    public void iOnClickToAlone(UnCompleteBean unCompleteBean) {
        // 跳转到对应的检测点
        if (iOnJumpToItem != null) {
            iOnJumpToItem.iOnJumpToItem(unCompleteBean);
        }
        dismiss();
    }

    IOnJumpToItem iOnJumpToItem;

    public X3UnCompleteDialog setiOnJumpToItem(IOnJumpToItem iOnJumpToItem) {
        this.iOnJumpToItem = iOnJumpToItem;
        return this;
    }

    public interface IOnJumpToItem {
        void iOnJumpToItem(UnCompleteBean unCompleteBean);
    }
}
